/*
 * Golosina.cpp
 *
 *  Created on: 23/10/2013
 *      Author: fernando
 */

#include "Golosina.h"
#include "SDL.h"
#include <vector>

using std::vector;

Golosina::Golosina() {
}


Golosina::~Golosina() {
	for (vector<SDL_Surface*>::iterator It = secDestruccion.begin();
				It != secDestruccion.end(); ++It){
		SDL_FreeSurface(*It);
	}
	SDL_FreeSurface(imagen);
}



void Golosina::dibujar(SDL_Surface* screen, bool destruir){
	if (!destruir){
		////	Pone como transparente el color negro
		SDL_SetColorKey(imagen , SDL_SRCCOLORKEY, SDL_MapRGB(imagen->format, 0, 0, 0));
		SDL::apply_surface(posX, posY, imagen, screen, NULL);
	}else{
		for (vector<SDL_Surface*>::iterator It = secDestruccion.begin();
					It != secDestruccion.end(); ++It){
			SDL::apply_surface(posX, posY, (*It), screen, NULL);
			SDL_Flip(screen);
			SDL_Delay(20);
		}
	}
}

unsigned int Golosina::getPosX(){
	return posX;
}

unsigned int Golosina::getPosY(){
	return posY;
}

void Golosina::setPosicion(unsigned int x, unsigned int y){
	posX = x;
	posY = y;
}


SDL_Surface* Golosina::getImagen(){
	return imagen;
}

int Golosina::getColor(){
	return color;
}

std::string Golosina::itoa(int n){
	std::string rtn;
	for(rtn="";n>0;rtn.insert(rtn.begin(),n%10+'0'),n/=10);
	return rtn;
}
